package com.example.javamaday.leetcode;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.List;

public class LeetCodeTest0017 {

    public static void main(String[] args) {

        new LeetCodeTest0017().letterCombinations("23");

    }

    public List<String> letterCombinations(String digits) {
        // 空内容判断
        if (digits.length() == 0) {
            return new ArrayList<>();
        }
        char[] array = digits.toCharArray();
        String[][] strArray = new String[array.length][4];
        for (int i = 0; i < array.length; i++) {
            strArray[i] = getNumContent(Integer.parseInt(String.valueOf(array[i])));
        }
        System.out.println(Arrays.deepToString(strArray));
        List<String> result = new LinkedList<>(Arrays.asList(strArray[0]));
        int index = 1;
        while (index < strArray.length) {
            while (result.get(0).length() == index) {
                for (int i = 0; i < strArray[index].length; i++) {
                    result.add(result.get(0) + strArray[index][i]);
                }
                result.remove(0);
            }
            index++;
        }

        return result;
    }


    private String[] getNumContent(int i) {
        if (i == 2) {
            return new String[]{"a", "b", "c", "-"};
        } else if (i == 3) {
            return new String[]{"d", "e", "f", "-"};
        } else if (i == 4) {
            return new String[]{"g", "h", "i", "-"};
        } else if (i == 5) {
            return new String[]{"j", "k", "l", "-"};
        } else if (i == 6) {
            return new String[]{"m", "n", "o", "-"};
        } else if (i == 7) {
            return new String[]{"p", "q", "r", "s"};
        } else if (i == 8) {
            return new String[]{"t", "u", "v", "-"};
        } else if (i == 9) {
            return new String[]{"w", "x", "y", "z"};
        }
        return new String[]{"-", "-", "-", "-"};
    }


}
